<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="../WEB-INF/jspf/controlesessao.jspf"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Alterar Docente</title>
        <script type="text/javascript" src="../js/jquery.js" ></script>
        <script type="text/javascript" src="../js/jquery-ui-1.8.2.custom.min.js" ></script>
        <script type="text/javascript" src="../js/jquery.validate.js"></script>
        <script type="text/javascript" src="../js/jquery.ui.datepicker-pt-BR.js" ></script>
        <script type="text/javascript" src="../js/forms.js"></script>
        <link rel="stylesheet" href="../css/forms.css">
        <link rel="stylesheet" href="../css/ui-lightness/jquery-ui-1.8.2.custom.css">
    </head>
    <script>
        var item=0;
        $(document).ready(function()
        {
            $("#form").validate({
                rules: {
                    matricula: {required: true}
                    ,nome: {required: true}
                    ,email: {required: true,email:true}
                    ,cargo: {required: true}
                    ,formacao: {required: true}
                    ,situacao: {required: true}
                },
                submitHandler: function(form) {
                    salvar(form);
                }
            });
            $("a#novocurso").click( function(){ $("#cursos").slideDown(500); addLinha();  })
        });
        function addLinha(){
            item=item+1;
            var txt =$('#linha').html().replace(/item/gi, item);
            txt  = '<tr>'+
                '<input type="hidden" name="itens" value="'+item+'">'+
                txt
                +'</tr>';

            $('#tabcursos > tbody:last').append( txt );
        };

        function remover(id) {
            $(id).parent().parent().remove();
        }


        $(function() {
            $("#tabs").tabs({ajaxOptions: {
                    error: function(xhr, status, index, anchor) {
                        $(anchor.hash).html("O recurso não pode ser encontrado.");
                    }
                }
            });
        });

    </script>

    <body>
        <div id="formulario">
            <form name="form" id="form" method="post" action="update.jsp" >
                <div id="tabs">
                    <ul>
                        <li><a href="#tabdados">Dados Pessoais</a></li>
                        <li><a href="#tabcursos">Cursos</a></li>
                        <li><a href="#tabcompetencias">Competencias</a></li>
                        <li><a href="#tabcomponentes">Componentes</a></li>
                        <li><a href="#tabafastamentos">Atividade extra-classe</a></li>
                    </ul>
                    <div id="tabdados">
                        <p>
                            <sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
                                SELECT  * FROM Docentes where matricula =?
                                <sql:param value="${param.chave}"/>
                            </sql:query>
                            <c:forEach var="row" items="${query.rows}">
                                <p><label class="lbInput">Matrícula<em>*</em></label>
                                    <input type="text" name="matricula" readonly size="6" maxlength="6" class="required" value="${row.matricula}">
                                </p>
                                <p><label class="lbInput">Nome<em>*</em></label>
                                    <input type="text" name="nome" size="80" readonly  class="required" value="${row.nome}">
                                </p>
                                <p><label class="lbInput">E-mail<em>*</em></label>
                                    <input type="text" id="email" name="email" size="80"   class="required" value="${row.email}">
                                </p>
                                <p><label class="lbInput">Situação </label>

                                        <select name="ativo">
                                            <option value="S" ${row.situacao=='S'?'selected':''}>Ativo</option>
                                            <option value="N" ${row.situacao=='N'?'selected':''}>Inativo</option>
                                        </select>

                                </p>
                                <p><label class="lbInput">Turno </label><br>
                                    <sql:query var="queryTurno" dataSource="jdbc/dbo_MicrosoftSQLServer">
                                        SELECT  Turnos.* , matricula FROM Turnos
                                        left join Turnos_Docentes d on turnos.id_turno=d.id_turno and d.matricula =?
                                        <sql:param value="${row.matricula}"/>
                                    </sql:query>
                                    <c:forEach var="turnos" items="${queryTurno.rows}">
                                        <input name="id_turno" type="radio"  ${turnos.matricula==null?'':'checked'}
                                               value="${turnos.id_turno}"><label class="lbInput">${turnos.desc_turno}</label><br>
                                    </c:forEach>
                                </p>
                            </c:forEach>
                        </p>
                    </div>
                    <div id="tabcursos" style="font-size:58%">
                        <c:forEach var="row" items="${query.rows}">
                            <p>
                                <p> <a href="#" id="novocurso"> Novo Curso </a>
                                </p>
                                <p>
                                    <div id="cursos" style="display:block">
                                        <table id="tabcursos">
                                            <thead>
                                                <th>Curso</th>
                                                <th>PCDA</th>
                                                <th>Valor</th>
                                                <th>Instituição</th>
                                                <th>Data Início</th>
                                                <th>Data Conclusão</th>
                                                <th>Descrição</th>
                                                <th>Carga Horária</th>
                                                <th></th>
                                            </thead>
                                            <tbody>
                                                <sql:query var="quCursos" dataSource="jdbc/dbo_MicrosoftSQLServer">
                                                    SELECT  c.*, f.*, t.desc_tipocursoF
                                                    FROM CursosF c
                                                    inner join Formacoes f on f.id_cursosF=c.id_cursosF
                                                    inner join tipocursoF t on c.id_tipocursof=t.id_tipocursoF
                                                    where matricula=?
                                                    order by desc_cursof
                                                    <sql:param value="${row.matricula}"/>
                                                </sql:query>
                                                <c:forEach var="cursos" items="${quCursos.rows}">
                                                    <tr>
                                                        <td>
                                                            <input name="itens" value="${cursos.id_cursosF}" type="hidden">
                                                            <input name="id_cursosF_${cursos.id_cursosF}" value="${cursos.id_cursosF}" type="hidden">
                                                            ${cursos.desc_tipocursof}-${cursos.desc_cursof}
                                                        </td>
                                                        <td><input type="checkbox" name="pdca_${cursos.id_cursosF}" ${cursos.pdca=='S'?'checked':''} value="S"> </td>
                                                        <td>
                                                            <fmt:formatNumber value="${cursos.valor}" pattern="##,###.00#" var="valor"/>
                                                            <input type="text" name="valor_${cursos.id_cursosF}" value="${valor}" >
                                                        </td>
                                                        <td><input type="text" name="instituicao_${cursos.id_cursosF}" value="${cursos.instituicao}" class="required"></td>
                                                        <td><input type="text" name="data_inicio_${cursos.id_cursosF}" value="${cursos.data_inicio}" class="required"></td>
                                                        <td><input type="text" name="data_fim_${cursos.id_cursosF}" value="${cursos.data_fim}" class="required"></td>
                                                        <td><input type="text" name="desc_formacao_${cursos.id_cursosF}" value="${cursos.desc_formacao}" class="required"></td>
                                                        <td><input type="text" name="carga_horaria_${cursos.id_cursosF}" value="${cursos.carga_horaria}" class="required"></td>
                                                        <td><img src="../imagens/Delete.png" onclick="remover(this)"></td>
                                                    </tr>
                                                </c:forEach>
                                            </tbody>

                                        </table>
                                    </div>
                                </p>

                            </p>
                        </c:forEach>
                    </div>
                    <div id="tabcompetencias">
                        <iframe name="frame_afastamentos" src="../Competencias_Docentes/fm_lista_Competencias_Docentes.jsp?token=${sessionScope.token}&matricula=${param.chave}"
                                width="100%" height="600px" frameborder="0">
                        </iframe>
                    </div>
                    <div id="tabafastamentos">
                        <iframe name="frame_afastamentos" src="../Afastamentos/fm_lista_Afastamentos.jsp?token=${sessionScope.token}&matricula=${param.chave}"
                                width="100%" height="600px" frameborder="0">
                        </iframe>
                    </div>
                    <div id="tabcomponentes">
                        <iframe name="frame_componentes" src="fm_componentes_docentes.jsp?token=${sessionScope.token}&matricula=${param.chave}"
                                width="100%" height="600px" frameborder="0">
                        </iframe>
                    </div>
                </div>

                <p>
                    <input class="submit" type="submit" value="Salvar Docente">
                    <input class="submit" type="button" value="Consultar Docentes" onclick="listar('fm_lista_Docentes.jsp')">
                </p>
                <div id="ajax_dados" style="display:block">
                </div>
                <div id="msg" style="display:inline"></div>

            <input type="hidden" id="token" name="token" value="${sessionScope.token}" /> </form>
            <div id="linha" style="visibility:hidden">

                <td>
                    <sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
                        SELECT  * FROM CursosF
                        inner join tipocursoF on CursosF.id_tipocursof=tipocursoF.id_tipocursoF
                        order by desc_cursof
                    </sql:query>
                    <select name="id_cursosF_item" id="cursos" class="required">
                        <option value="" selected>Selecione um valor</option>
                        <c:forEach var="row" items="${query.rows}">
                            <option value="${row.id_cursosF}">${row.desc_tipocursof}-${row.desc_cursof}</option>
                        </c:forEach>
                    </select>

                </td>
                <td><input type="checkbox" name="pdca_item" value="S"> </td>
                <td><input type="text" name="valor_item" value="" size="10"> </td>
                <td><input type="text" name="instituicao_item" value="" class="required"></td>
                <td><input type="text" name="data_inicio_item" value="" size="11" class="required"></td>
                <td><input type="text" name="data_fim_item" value="" size="11" class="required"></td>
                <td><input type="text" name="desc_formacao_item" value="" class="required"></td>
                <td><input type="text" name="carga_horaria_item" value="" size="10" class="required"></td>
                <td><img src="../imagens/Delete.png" onclick="remover(this)"></td>
            </div>
        </div>
    </body>
</html>
